package org.medusa.core;

import java.util.concurrent.LinkedBlockingQueue;

public class Channel<Element extends Object>  {
	
	private LinkedBlockingQueue<Element> queue;
	
	public Channel() {
		this.queue = new LinkedBlockingQueue<Element>();
	}
	
	public Element Read() {
		Element obj = null;
		try {
			obj = this.queue.take();
		} catch (InterruptedException e) {
			
		}
		
		return obj;
	}
	
	public boolean Write(Element val) {
		return val==null ? false : this.queue.add(val);
		/*
		try {
			this.aaa.put(val);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
	}
	
	public void Clear() {
		this.queue.clear();
	}
	
	public int Size() {
		return this.queue.size();
	}

}
